/**
 * 数组分组
 */
export const groupBy = (array, f) => {
    const groups = {}
        array.forEach(function (o) {
            const group = JSON.stringify(f(o))
            groups[group] = groups[group] || []
            // if (!o.hide) {
                groups[group].push(o)
            // }
            
        });
        return Object.keys(groups).map(function (group) {
            return groups[group]
        }); 
}
/**
 * 获取随机数
 * @param {位数} num 
 * @returns 
 */
export const getRandom = (num) => {
    return Math.floor((Math.random()+Math.floor(Math.random()*9+1))*Math.pow(10,num-1))
}

export const download = (stream, name) => {
    const link = document.createElement("a");
    let blob = new Blob([stream]);//生成blob对象
    link.style.display = "none";
    link.href = URL.createObjectURL(blob);
    link.setAttribute("download", name); //下载的文件名以及文件格式
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}